package reduce.fz.com.reduce.custom;

import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.TypeReference;

import java.util.HashMap;

import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.abstracts.AbResponseListener;
import reduce.fz.com.reduce.bean.ServiceException;
import reduce.fz.com.reduce.bean.User;
import reduce.fz.com.reduce.bean.result.Result;
import reduce.fz.com.reduce.service.UserService;
import reduce.fz.com.reduce.util.ServiceBuilder;

/**
 * Created by qingshengzheng on 16/1/10.
 * 赞视图
 */
public class PraiseView extends TextView {
    public PraiseView(Context context) {
        super(context);
    }/*
    private User me;
    private User owner;
    private Long mid;
    private Long uid;
    //当前状态
    private Boolean isPraise = false;
    private UserService userService = ServiceBuilder.builderUserService(null);

    public PraiseView(Context context) {
        super(context);
    }

    public PraiseView(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    public PraiseView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void init(User owner) {
        this.owner = owner;
        this.isPraise = owner.userAttach.ispraise;
        resetStatus();
    }


    public void initListener() {
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                praise(!isPraise);
            }
        });

    }


    private void resetStatus() {

        this.setText(owner.userAttach.praise_num+"");
        setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.text_33));
        if (owner.userAttach.ispraise) {
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.zan_red16, 0, 0, 0);
            setSelected(true);
        } else {
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.zan_black16, 0, 0, 0);
            setSelected(false);
        }

    }


    public void praise(final Boolean isPraise) {
        if (owner == null) return;
        userService.userpraise(owner.uid, isPraise, new AbResponseListener<HashMap>(new TypeReference<Result<HashMap>>() {
        }) {
            @Override
            public void error(ServiceException e) {

            }

            @Override
            public void responseInfo(Result<HashMap> data) {
                if (isPraise) {
                    owner.userAttach.ispraise = true;
                    owner.userAttach.praise_num++;
                    resetStatus();
                } else {
                    owner.userAttach.ispraise = false;
                    owner.userAttach.praise_num--;
                    resetStatus();
                }


            }
        });


    }*/


}
